import random

from gloal.mqtt import connect_mqtt

client_id = f'python-mqtt-{random.randint(0, 100)}'

topic = "h2s/mqtt/+"

def subscribe(client):
    def on_message(client, userdata, msg):
        print(f"Received `{msg.payload.decode()}` from `{msg.topic}` topic")

    client.subscribe(topic)
    client.on_message = on_message


def run():
    client = connect_mqtt(client_id)
    subscribe(client)
    client.loop_forever()


if __name__ == '__main__':
    run()
